// 用着挺好
divide(3, 1)
  .then((res) => console.log(`Get: ${res}`))
  .catch((err) => console.log(`Failed: ${err}`));

// 测试下错误情况
divide(3, 0)
  .then((res) => console.log(`Get: ${res}`))
  .catch((err) => console.log(`Failed: ${err}`));

divide("asd", "asd")
  .then((res) => console.log(`Get: ${res}`))
  .catch((err) => console.log(`Failed: ${err}`));

// 一个简单的除法程序改进版
function divide(numerator, denominator) {
  return new Promise((resolve, reject) => {
    if (typeof numerator !== "number" || typeof denominator !== "number") {
      reject(new TypeError("Must be number!"));
    }
    if (denominator === 0) {
      reject(new Error("Cannot divide by 0!"));
    }
    resolve(numerator / denominator);
  });
}
